package entidade;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

//import testeBlog.Author;
//import testeBlog.Blog;
//import testeBlog.Entry;

import com.thoughtworks.xstream.XStream;
import java.util.Iterator;

public class TesteXStreamProjeto {

    public static void main(String[] args) {
        //Blog teamBlog = new Blog(new Author("Guilherme Silveira"));
        List root = new ArrayList();
        Atributo atributo = new Atributo();
        atributo.setNome("idade");
        atributo.setValor(Integer.valueOf(23));

        Atributo atributo2 = new Atributo();
        atributo2.setNome("cpf");
        atributo2.setValor(Integer.valueOf(13332342));

        Entidade ent = new Entidade();
        ent.setNome("Aluno");
        ent.adicionarAtributo(atributo);
        ent.adicionarAtributo(atributo2);

        root.add(ent);

        XStream xstream = new XStream();
        xstream.alias("root", List.class);
        xstream.alias("Atributo", Atributo.class);
        xstream.alias("Entidade", Entidade.class);
        // xstream.addImplicitCollection(ArrayList.class, "root");


        //xstream.addImplicitCollection(Entidade.class, "atributos");

        //  xstream.useAttributeFor(Blog.class, "author");
        //   xstream.registerConverter(new AuthorConverter());
        System.out.println(xstream.toXML(root));
        List l = (List<Entidade>) xstream.fromXML("" + xstream.toXML(root));
        Entidade ent1 = (Entidade) l.get(0);
        HashMap<String, IAtributo> atributosEnt1 = ent1.getAtributos();
        for (Iterator it = atributosEnt1.values().iterator(); it.hasNext();) {
            IAtributo at = (IAtributo) it.next();
            System.out.println(at.getNome());
            System.out.println(at.getValor().toString());
            System.out.println("");
        }
    }
}
